package org.example.game.weekly.game409;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/08/03 20:45
 */
public class Solution001 {
    public static HashMap<Integer, List<Integer>> pointMap = new HashMap<>();
    //adjacentSum 0  diagonalSum 1

    public static void main(String[] args) {
        new Solution001().neighborSum(new int[][]{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}});
//        System.out.println(pointMap.size());
        System.out.println(new Solution001().adjacentSum(1));
        System.out.println(new Solution001().adjacentSum(4));
        System.out.println(new Solution001().diagonalSum(4));
        System.out.println(new Solution001().diagonalSum(8));
    }



    public void neighborSum(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                int adjacentSum = 0;
                if(i>0){
                    adjacentSum+=grid[i-1][j];
                }
                if(j>0){
                    adjacentSum+=grid[i][j-1];
                }

                if(i<m-1){
                    adjacentSum+=grid[i+1][j];
                }

                if(j<n-1){
                    adjacentSum+=grid[i][j+1];
                }

                int diagonalSum = 0;
                if(i>0 && j>0){
                    diagonalSum+=grid[i-1][j-1];
                }
                if(i<m-1 && j<n-1){
                    diagonalSum+=grid[i+1][j+1];
                }

                if(i>0 && j<n-1){
                    diagonalSum+=grid[i-1][j+1];
                }
                if(i<m-1 && j>0){
                    diagonalSum+=grid[i+1][j-1];
                }

                List<Integer> res = new ArrayList<>();
                res.add(adjacentSum);
                res.add(diagonalSum);
                pointMap.put(grid[i][j], res);

            }
        }
    }

    public int adjacentSum(int value) {
        return pointMap.get(value).get(0);
    }

    public int diagonalSum(int value) {
        return pointMap.get(value).get(1);
    }

}


/**
 * Your neighborSum object will be instantiated and called as such:
 * neighborSum obj = new neighborSum(grid);
 * int param_1 = obj.adjacentSum(value);
 * int param_2 = obj.diagonalSum(value);
 */